/*
 * @lc app=leetcode.cn id=1502 lang=typescript
 *
 * [1502] 判断能否形成等差数列
 */

// @lc code=start
function canMakeArithmeticProgression(arr: number[]): boolean {
    const list = arr.sort((a, b) => a - b);
    let step = undefined as undefined | number;
    for (let i = 1; i < list.length; i++) {
        const prev = list[i - 1];
        const element = list[i];
        if (step === undefined) {
            step = element - prev;
        } else if (element - prev !== step) {
            return false;
        }
    }
    return true;
}
// @lc code=end
